<?php
/**
 * Created by PhpStorm.
 * User: wangwenfan
 * Date: 2018/7/27
 * Time: 18:16.
 */

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Base\Charge;
use App\Models\Base\LogChannelDataStat;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;

class ChannelStatController extends Controller
{
    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header(trans('game.data_statistic'));
            $content->description(trans('game.base_data'));

            $content->body($this->grid());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(LogChannelDataStat::class, function (Grid $grid) {
            $grid->model()->orderBy('date_time', 'desc');
            $grid->date_time(trans('game.date'))->sortable();
            $grid->channelName()->name(trans('game.channel'));
            $grid->new_player_num(trans('game.new_user'));
            $grid->new_role_num(trans('game.new_role'));
            $grid->login_player_num(trans('game.login_user'));
            $grid->amount(trans('game.amount'));
            $grid->pay_player_num(trans('game.pay_user_number'));
            $grid->pay_player_ratio(trans('game.pay_rate'))->display(function ($ratio) {
                return $ratio;
            });
            $grid->new_player_pay_num(trans('game.pay_new_user_no'));
            $grid->new_player_amount(trans('game.new_user_amount'));
            $grid->new_player_ltv(trans('game.new_user_one_day_ltv'));
            $grid->old_player_pay_num(trans('game.pay_old_user_no'));
            $grid->old_player_amount(trans('game.old_user_amount'));
            $grid->arpu();
            $grid->arppu();
            $grid->disableCreateButton();
            $grid->disableActions();
            $grid->tools(function ($tools) {
                $tools->batch(function ($batch) {
                    $batch->disableDelete();
                });
            });
            $grid->filter(function ($filter) {
                // 去掉默认的id过滤器
                $filter->disableIdFilter();
                $filter->between('date_time', trans('game.date'))->date();
                $filter->equal('channel_id', trans('game.channel'))->select(Charge::all()->where('pid', '>', 0)
                    ->pluck('name', 'channel_no'));
            });
        });
    }
}
